package com.ny.Demo036;

import java.util.ArrayList;
import java.util.Scanner;

class Employee {
    private int id;
    private String name;
    private int age;

    public Employee(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class Emp {
    private ArrayList<Employee> employees = new ArrayList<>();
    private Scanner scanner = new Scanner(System.in);
    public void add() {
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第 " + (i + 1) + " 个员工的编号：");
            int id = scanner.nextInt();
            System.out.println("请输入第 " + (i + 1) + " 个员工的姓名：");
            String name = scanner.next();
            System.out.println("请输入第 " + (i + 1) + " 个员工的年龄：");
            int age = scanner.nextInt();
            Employee employee = new Employee(id, name, age);
            employees.add(employee);
        }
    }


    public void get() {
        for (Employee employee : employees) {
            System.out.println(employee);
        }
    }


    public void remove() {
        System.out.println("请输入要删除员工的编号：");
        int id = scanner.nextInt();
        for (int i = 0; i < employees.size(); i++) {
            if (employees.get(i).getId() == id) {
                employees.remove(i);
                System.out.println("员工已成功删除");
                return;
            }
        }
        System.out.println("未找到对应员工");
    }


    public void set() {
        System.out.println("请输入要修改员工的编号：");
        int id = scanner.nextInt();
        for (Employee employee : employees) {
            if (employee.getId() == id) {
                System.out.println("请输入新的姓名：");
                String newName = scanner.next();
                System.out.println("请输入新的年龄：");
                int newAge = scanner.nextInt();
                employee = new Employee(id, newName, newAge);
                System.out.println("员工信息已修改");
                return;
            }
        }
        System.out.println("未找到对应员工");
    }


    public void clean() {
        employees.clear();
        System.out.println("所有员工信息已删除");
    }

    public static void main(String[] args) {
        Emp management = new Emp();
        Scanner input = new Scanner(System.in);
        boolean flag = true;
        while (flag) {
            System.out.println("请选择操作：");
            System.out.println("1. 添加3个员工信息: add");
            System.out.println("2. 查询所有的员工信息: get");
            System.out.println("3. 删除某一个员工信息: remove");
            System.out.println("4. 修改某个员工的信息: set");
            System.out.println("5. 删除所有员工信息: clean");
            System.out.println("请输入操作指令：");
            String operation = input.next();
            switch (operation) {
                case "add":
                    management.add();
                    break;
                case "get":
                    management.get();
                    break;
                case "remove":
                    management.remove();
                    break;
                case "set":
                    management.set();
                    break;
                case "clean":
                    management.clean();
                    break;
                default:
                    System.out.println("无效指令，请重新输入");
            }
        }
    }
}